import React from 'react';
import { BrowserRouter as Router, Switch, Route, Redirect } from 'react-router-dom';
import Login from './layout/login';
import Main from './layout/main/index';

function App() {
  return (
    <Router>
      <Switch>
        <Route path='/login' exact component={Login} />
        <Route
          path='/'
          render={() => {
            return localStorage.getItem('loginState') === 'true' ? (
              <Main />
            ) : (
              <Redirect to='/login' />
            );
          }}
        />
      </Switch>
    </Router>
  );
}

export default App;
